package com.violet.domain.result;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.violet.domain.emuns.Code;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
public class ResultPage<E> extends Result<E> {

    private long total;              // 总条数
    private long currentPage;        // 当前页码
    private long pageSize;           // 每页条数
    private long pages;              // 总页码

    private ResultPage(E data, String message, long total, long currentPage, long pageSize, long pages, int code) {
        super(data, message, code);
        this.total = total;
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.pages = pages;
    }



// ===================================== success =====================================

    public static <E> ResultPage<E> success(E data, String message, Page<?> page) {
        return new ResultPage<>(
            data,
            message,
            page.getTotal(),
            page.getCurrent(),
            page.getSize(),
            page.getPages(),
            Code.SUCCESS.code
        );
    }

}
